#ifndef INPUT_H_
#define INPUT_H_

#ifndef COMMON_H_
#   include "common.h"
#endif

#define TK_EOF          0
#define TK_IDENT       -1
#define TK_ACTION      -2
#define TK_SECTION     -3
#define TK_NOTUSED     -4
#define TK_ILLEGAL     -5
#define TK_QUOTED      -6
#define TK_LEFT        -7
#define TK_RIGHT       -8
#define TK_NONASSOC    -9
#define TK_TOKEN      -10
#define TK_NEWLINE    -11
#define TK_BADQUOTE   -12       /* found a single quote, but not terminated     */
#define TK_OPERAND    -13
#define TK_TEST       -14       /* %test [error# [line#]]                       */
#define TK_LINE       -15       /* pseudo-token (rest of line)                  */
#define TK_START      -16       /* pseudo-token (name of implicit start symbol  */
#define TK_CODE       -17       /* %{...%}                                      */
#define TK_PROGRAM    -18
#define TK_NONTERM    -19       /* TK_IDENT followed by ':' */

//#define TK_EOL        -25
#define TK_MATCHANY   -26
#define TK_NOACT      -27
#define TK_COMMENT    -28
#define TK_WHITESPACE -29
#define TK_OPERATOR   -30

typedef struct  INPUT_
    {
    void*       Dummy_;
    }           INPUT_, *INPUT;

typedef struct  TToken
    {
    const char* Text;
    size_t      TextLen;
    int         Type;
    }           TToken;

typedef struct  TContext
    {
    const char* LineStart;
    int         LineLen;
    int         LineNumber;
    }           TContext;

int         TokenEqual(TToken A, TToken B);
TToken      TokenFake(int Type, const char* Format, ...);

int         InputCreate(const char* Filename);
void        InputDestroy(void);
int         InputIsFake(TToken Token);
TToken*     InputGetTokens(void);
int         InputGetChar(void);
TToken      InputGetNext(void);
TToken      InputGetLine(void);
TToken      InputPrecGetNext(void);
TToken      InputPeekNext(void);
TContext    InputGetContext(const char* Text);
//void        InputError(INPUT Input, const char* Text);

int         InputGetLineNumber(const char* Text);
const char* InputGetLineStart(const char* Text);

extern  TToken  EOFToken;
extern  TToken  EOLToken;
extern  TToken  MatchAnyToken;
extern  TToken  NoActionToken;
extern  TToken  StartToken;
extern  TToken  ReduceToken;
extern  TToken  DefActToken;    /* name of default action */
#endif

